package com.example.shushiyunsst.fragment.main.mine.child

import android.graphics.Bitmap
import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import com.example.library_common.base.BaseDataBindingFragment
import com.example.library_common.base.BaseFragmentEx
import com.example.library_common.utils.PixUtils
import com.example.shushiyunsst.R
import com.example.shushiyunsst.databinding.SharePostFragmentBinding

import com.example.shushiyunsst.util.EncodingHandler
import com.example.shushiyunsst.util.clipboard
import com.example.wallet.db.UserInfoManager

class SharePostFragment :BaseDataBindingFragment<SharePostFragmentBinding>(), View.OnClickListener,ShareLabel {

    companion object{
        fun newInstance(): SharePostFragment {
            val args = Bundle()
            val fragment = SharePostFragment()
            fragment.arguments = args
            return fragment
        }
    }
    override fun labelInfo(): String {
      return "分享海报"
    }
    override fun layoutId(): Int {
        return R .layout.share_post_fragment
    }

    private var path = ""

    private var createQRCode: Bitmap? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport=false
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
//        val mToolbar: Toolbar = view.findViewById(R.id.mToolbar)
//        mToolbar.title = "分享推广"
//        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }

        viewBinder.onViewClick = this
        val userInfoManager = UserInfoManager.userInfoManager
        val userInfoWrapper = userInfoManager.getUserInfoWrapper()
        val userInfo = userInfoWrapper?.userInfo
        viewBinder.tvMCoding.text = "您的邀请码：${userInfo?.invitationCode}"


        try {
//            val str="http://token.regyun.com/download/sstwallet.apk"
            val code = userInfoManager.getUserInfoWrapper()?.userInfo?.invitationCode
            path =
//                "http://app.regyun.com/index.html?code=${code}"
//                "http://app.regyun.com/regys/index2.html?code=${code}"
                "http://app.regyun.com/regys/index.html?code=${code}"


            createQRCode =
                EncodingHandler.createQRCode(path, PixUtils.dp2px(170))

            viewBinder.mCoding.setImageBitmap(createQRCode)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.bottom -> {

            }
            R.id.mCopyTv -> {
//                val userInfoManager = UserInfoManager.userInfoManager
//                val userInfoWrapper = userInfoManager.getUserInfoWrapper()
//                val userInfo = userInfoWrapper?.userInfo
                clipboard("path",path)
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (createQRCode?.isRecycled == false) {
            createQRCode?.recycle()
        }
    }


}